﻿'Author: Justin Bassett
'Date: 1/12/08

Public Class frmHighScores

    Private Sub frmHighScores_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        frmMultiplicationPractice.Show()
    End Sub

    Private Sub frmHighScores_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        updateHighScores()
    End Sub

    Public Sub updateHighScores()
        Dim HighScores(,) As String = frmMultiplicationPractice.HighScore
        Me.lblNames.Text = "Name:" & vbNewLine
        Me.lblScore.Text = "Score:" & vbNewLine
        Me.lblDate.Text = "Date:" & vbNewLine
        For i As Integer = 0 To HighScores.GetLength(0) - 1
            Me.lblNames.Text &= (i + 1) & ") " & HighScores(i, 0) & vbNewLine
            Me.lblScore.Text &= HighScores(i, 1) & vbNewLine
            Me.lblDate.Text &= HighScores(i, 2) & vbNewLine
        Next i
    End Sub

    Public Sub addToHighScore(ByVal name, ByVal score)
        Dim newHighScoreList(4, 2) As String
        Dim oldListIndex As Integer = 0
        For i As Integer = 0 To 4
            If score < frmMultiplicationPractice.HighScore(i, 1) Or i <> oldListIndex Then
                newHighScoreList(i, 0) = frmMultiplicationPractice.HighScore(oldListIndex, 0)
                newHighScoreList(i, 1) = frmMultiplicationPractice.HighScore(oldListIndex, 1)
                newHighScoreList(i, 2) = frmMultiplicationPractice.HighScore(oldListIndex, 2)
                oldListIndex += 1
            Else
                newHighScoreList(i, 0) = name
                newHighScoreList(i, 1) = score
                newHighScoreList(i, 2) = Date.Now.Date
            End If
        Next i
        frmMultiplicationPractice.HighScore = newHighScoreList
        updateHighScores()
        Me.Show()
    End Sub

    Private Sub btnContinue_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnContinue.Click
        frmMultiplicationPractice.Show()
        Me.Hide()
    End Sub
End Class